package com.wuxiaofan.api;

import com.alibaba.fastjson.JSONObject;
import com.wuxiaofan.entity.model.HospitalSetMongo;
import com.wuxiaofan.service.HospitalSetService;
import com.wuxiaofan.vo.ReturnResult;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wuxiaofan
 * @date 2021/11/4 8:33 下午
 */
@Slf4j
@RestController
@RequestMapping("hospitalmongo")
public class HospitalMongoApi {

    @Resource
    private HospitalSetService hospitalSetService;


    @PostMapping("save")
    public ReturnResult save(@RequestBody JSONObject jsonObject){
        log.info("jsonObject:{}",jsonObject);
        HospitalSetMongo hospitalSetMongo = JSONObject.parseObject(jsonObject.toJSONString(),HospitalSetMongo.class);
        hospitalSetService.save(hospitalSetMongo);
        return ReturnResult.success("保存成功");
    }

    @GetMapping("list")
    public ReturnResult list(@PathVariable("hoscode")String hoscode){
        HospitalSetMongo hospitalSetMongo = hospitalSetService.getByHoscode(hoscode);
        return ReturnResult.success("按照hoscode查询成功",hospitalSetMongo);
    }


    @GetMapping("queryByHoscode/{hoscode}")
    public ReturnResult queryByHoscode(@PathVariable("hoscode")String hoscode){
        HospitalSetMongo hospitalSetMongo = hospitalSetService.getByHoscode(hoscode);
        return ReturnResult.success("按照hoscode查询成功",hospitalSetMongo);
    }


}
